package com.gome.ocean.service.websql.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.gome.ocean.dao.datax.GUserFrequentlySqlDAO;
import com.gome.ocean.dao.model.websql.GUserFrequentlySql;
import com.gome.ocean.service.websql.SqlHandleService;

/**
 * @author liyuefeng
 */
@Service("SqlHandleServiceImpl")
public class SqlHandleServiceImpl implements SqlHandleService {

    private final static Logger   LOG = LoggerFactory.getLogger(SqlHandleServiceImpl.class);
    @Autowired
    private GUserFrequentlySqlDAO gUserFrequentlySqlDAO;

    @Override
    public boolean saveUserSql(GUserFrequentlySql frequentlySql) {
        try {
            gUserFrequentlySqlDAO.insertSelective(frequentlySql);
            return true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
            return false;
        }
    }

    @Override
    public List<GUserFrequentlySql> getUserFrequentlySqlByParam(Map<String, Object> param) {
        try {
            List<GUserFrequentlySql> frequentlySqls = gUserFrequentlySqlDAO.getUserFrequentlySqlByParam(param);
            return frequentlySqls;
        } catch (Exception e) {
            LOG.error(e.getMessage());
            return null;
        }
    }

    @Override
    public boolean removeUserSql(Long id) {
        try {
            gUserFrequentlySqlDAO.deleteByPrimaryKey(id);
            return true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
            return false;
        }
    }

    @Override
    public GUserFrequentlySql getGUserFrequentlySqlById(Long id) {
        try {
            GUserFrequentlySql gUserFrequentlySql = gUserFrequentlySqlDAO.selectByPrimaryKey(id);
            return gUserFrequentlySql;
        } catch (Exception e) {
            LOG.error(e.getMessage());
            return null;
        }
    }

    @Override
    public boolean updateByPrimaryKeySelective(GUserFrequentlySql record) {

        try {
            gUserFrequentlySqlDAO.updateByPrimaryKeySelective(record);
            return true;
        } catch (Exception e) {
            LOG.error(e.getMessage());
            return false;
        }

    }

    @Override
    public Page<GUserFrequentlySql> getUserFrequentlySqlByParam(int pageNum, int pageSize, Map<String, Object> param) {
        try {
            List<GUserFrequentlySql> frequentlySqls = gUserFrequentlySqlDAO
                .getUserFrequentlySqlByParam(new RowBounds(pageNum, pageSize), param);
            return (Page<GUserFrequentlySql>) frequentlySqls;
        } catch (Exception e) {
            LOG.error(e.getMessage());
            return null;
        }
    }

}
